package no.sachmuld.methodcombination.examples.annotation.combo;

import no.sachmuld.methodcombination.api.reflection.component.MethodCombination;
import no.sachmuld.methodcombination.impl.annotation.MethodCombinationImplementation;
import no.sachmuld.methodcombination.impl.annotation.MethodCombinationInitializer;

import java.lang.annotation.*;
import java.util.Map;

/**
 *
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@MethodCombinationImplementation(
        value = no.sachmuld.methodcombination.api.reflection.component.ContractCheckingMethodCombination.class,
        initializer = ContractChecking.Initializer.class,
        nested = no.sachmuld.methodcombination.api.reflection.component.MethodCombination.class
)
public @interface ContractChecking {

    public class Initializer implements MethodCombinationInitializer {
        @Override
        public void initialize(MethodCombination methodCombination, Annotation annotation, Map<Class<? extends MethodCombination>, MethodCombination> dependencyMap) {

            no.sachmuld.methodcombination.api.reflection.component.ContractCheckingMethodCombination contractCheckingMethodCombination = (no.sachmuld.methodcombination.api.reflection.component.ContractCheckingMethodCombination) methodCombination;
            MethodCombination nestedMethodCombination = dependencyMap.get(MethodCombination.class);

            contractCheckingMethodCombination.setTargetMethodCombination(nestedMethodCombination);

        }
    }

}
